home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
language
/
ici
/
ici.cpi
/
catch.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-27
|
2KB
|
99 lines
#include "exec.h"
#include "catch.h"
#include "op.h"
#include "func.h"
/*
* Unwind the execution stack until a catcher is found. Then unwind
* the scope and operand stacks to the matching depth (but only if it is).
* Returns the catcher, or NULL if there wasn't one.
*/
catch_t *
unwind()
{
object_t **p;
catch_t *c;
for (p = x_top - 1; p >= xs->a_base; --p)
{
if (iscatch(*p))
{
c = catchof(*p);
x_top = p;
o_top = &os->a_base[c->c_odepth];
v_top = &vs->a_base[c->c_vdepth];
NEXT_VSVER;
return c;
}
}
return NULL;
}
STATIC long
mark_catch(c)
catch_t *c;
{
long mem;
objof(c)->o_flags |= O_MARK;
mem = sizeof(catch_t);
if (c->c_catcher != NULL)
mem += mark(c->c_catcher);
return mem;
}
/*
* Note: catch's come back pre-loosed.
*/
catch_t *
new_catch(o, odepth, vdepth)
object_t *o;
int odepth;
int vdepth;
{
register catch_t *c;
if ((c = talloc(catch_t)) == NULL)
return NULL;
objof(c)->o_type = &catch_type;
objof(c)->o_tcode = TC_CATCH;
objof(c)->o_flags = 0;
objof(c)->o_nrefs = 0;/* Catch's are pre-loosened. Unlike other types. */
rego(c);
c->c_catcher = o;
c->c_odepth = odepth;
c->c_vdepth = vdepth;
return c;
}
/*
* runner handler => catcher (os)
* => catcher pc (xs)
* => catcher (vs)
*/
STATIC int
op_onerror()
{
if ((x_top[-1] = objof(new_catch(o_top[-1], o_top - os->a_base - 2, v_top - vs->a_base))) == NULL)
return 1;
if ((*x_top = objof(new_pc(arrayof(o_top[-2])))) == NULL)
return 1;
o_top -= 2;
++x_top;
return 0;
}
type_t catch_type =
{
mark_catch,
free_simple,
hash_unique,
cmp_unique,
copy_simple,
assign_simple,
fetch_simple,
"catch"
};
op_t o_onerror = {OBJ(TC_OP, op_type), op_onerror};